package com.atguigu.gmall.search.repository;

import com.atguigu.gmall.search.entity.News;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface NewRepository extends ElasticsearchRepository<News,Long> {
    //根据发布者名字查询
    List<News> findAllByPublisherNameEquals(String publisherName);
    //查询所有浏览量大于5 并且发布时间是三天前的所有新闻
    List<News> findAllByViewCountGreaterThanAndPubDateBefore(Integer viewCount,
                                                             Date pubDate);
    //仅限于单索引的简单查询
    long countAllByIdGreaterThan(long id);
    //jpa：Java Persistent API ： Java持久化API
    @Query("{\n" +
            "    \"match\": {\n" +
            "      \"pn\": \"?0\"\n" +
            "    }\n" +
            "  }")
    List<News> getYidui(String name);
}
